
package cuttings;

import java.io.*;
import java.net.*;
import java.util.*;


public class WelcomeConnection implements Runnable
{

    ServerSocket welcomeSocket;

    public WelcomeConnection(ServerSocket thisSocket)
    {
        this.welcomeSocket = thisSocket;
    }

    public void run()
    {
        try{
            processRequest();
        }
        catch (Exception e){
            System.out.println(e);
        }
    }


    private void processRequest() throws Exception
    {
        while(true)
        {
            Socket newConnection = welcomeSocket.accept();
            //save new peer's ip and welcome port no. in peers list

            createReceiveThread(newConnection);
        }

    }

    private void createReceiveThread(Socket newConnection)
    {
        ReceiveMsg request = new ReceiveMsg(newConnection);
        Thread receiveThread = new Thread(request);
        receiveThread.start();
    }



}


